home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / source.exe / POSIX / DEVSRV / DEVSRV.C next >
C/C++ Source or Header  |  1993-07-08  |  6KB  |  291 lines

  1. #if 0
  2. #include "d:\nt\public\sdk\inc\crt\sys\types.h"
  3. #include "d:\nt\public\sdk\inc\crt\sys\stat.h"
  4. #include "d:\ntnew\mstools\h\sys\types.h"
  5. #include "d:\ntnew\mstools\h\sys\stat.h"
  6. #endif
  7. #include <sys\types.h>
  8. #include <sys\stat.h>
  9. #include <sys\types.h>
  10. #include <sys\stat.h>
  11. #include <errno.h>
  12. #if 0
  13. #include <unistd.h>
  14. #endif
  15. #include <stdio.h>
  16. #include <process.h>
  17. #include <direct.h>
  18. #include <stdlib.h>
  19.  
  20.  
  21. char
  22.         *csp_ptr,
  23.     args[100][81],
  24.     *argp[100],
  25.     command[81],
  26.     *cPtr,
  27.     dir[81],
  28.     directory[81],
  29.     exe[81],
  30.     lib[256],
  31.     fn[50][81],
  32.     new[81],
  33.     old[81],
  34.     oldLibEnv[256],
  35.     curLibEnv[256],
  36.     tmp[81];
  37. int
  38.     i,
  39.     j,
  40.     len,
  41.     x,
  42.     y,
  43.     z;
  44.  
  45. main()
  46. {
  47.     if(cPtr = getenv("TMP"))    
  48.         strcpy(directory, cPtr);
  49.  
  50.     strcat(directory, "\\devsem.ini");
  51.     remove(directory);
  52.     for (;;)
  53.         check_status ();
  54. }
  55.  
  56. char *mystrstr(char *str,char *pat)
  57. {
  58.     struct _stat buff;
  59. #if 0
  60.     if ( _stat( str , & buff ) == -1 )
  61.        return ( char * ) NULL;
  62.     if ( buff.st_mode & _S_IFDIR )
  63.        return ( char * ) NULL;
  64. #endif
  65.     if ( strcmp( str + strlen(str) - strlen(pat) ,  pat ))
  66.        return ( char * ) NULL;
  67.     return str + strlen(str) - strlen(pat);
  68. }
  69.  
  70. check_status()
  71. {
  72. FILE     
  73.     *in, 
  74.     *out;
  75.  
  76.     while(!(in = fopen(directory, "r")))
  77.         _sleep(5);
  78.     
  79.     curLibEnv[0] = 0;
  80.     fscanf(in, "%s", exe);
  81.     if(!strcmp(exe, "LIB"))
  82.         {
  83.         fscanf(in, "%s", lib);
  84.         fscanf(in, "%s", exe);
  85.  
  86.         if(!strncmp(lib, "//", 2)) //Change drive letter format
  87.             {
  88.             strcpy(tmp, &(lib[3]));
  89.             lib[0] = lib[2];
  90.             lib[1] = ':';
  91.             lib[2] = 0;
  92.             strcat(lib, tmp);
  93.             for2bak(lib);
  94.             }
  95.  
  96.         if(cPtr = getenv("LIB"))    
  97.             strcpy(oldLibEnv, cPtr);
  98.  
  99.         strcpy(curLibEnv, "LIB=");
  100.         strcat(curLibEnv, lib); 
  101.         putenv(curLibEnv);
  102.         }
  103.     else
  104.         {
  105.         if(cPtr = getenv("POSIX_LIB"))    
  106.             strcpy(lib, cPtr);
  107.  
  108.         if(cPtr = getenv("LIB"))    
  109.             strcpy(oldLibEnv, cPtr);
  110.  
  111.         strcpy(curLibEnv, "LIB=");
  112.         strcat(curLibEnv, lib); 
  113.         putenv(curLibEnv);
  114.         }
  115.  
  116.     if(!strcmp(exe, "cwd"))
  117.         {
  118.         fscanf(in, "%s", tmp);
  119.         if(!strncmp(tmp, "//", 2)) //Change drive letter format
  120.             {
  121.             dir[0] = tmp[2];
  122.             dir[1] = ':';
  123.             dir[2] = 0;
  124.             strcat(dir, &(tmp[3]));
  125.             }
  126.         else
  127.             strcpy(dir, tmp);
  128.  
  129.         for2bak(dir);
  130.  
  131.         i = _chdir(dir);
  132.         i = errno;
  133.         }
  134.  
  135.     x=0;
  136.     y=0;
  137.     for (i=0; i < 100 && fscanf(in, "%s", args[i]) && !feof(in); i++)
  138.         {
  139.  
  140.         if(!strncmp(args[i], "//", 2)) //Change drive letter format
  141.             {
  142.             strcpy(args[i+1], &(args[i][3]));
  143.             args[i][0] = args[i][2];
  144.             args[i][1] = ':';
  145.             args[i][2] = 0;
  146.             strcat(args[i], args[i+1]);
  147.             for2bak(args[i]);
  148.             }
  149.  
  150.         if(strstr(args[i], "//", 2))
  151.             {
  152.             if(!strncmp(args[i], "/I", 2)) //Change drv letter fmt
  153.                 {
  154.                 strcpy(args[i+1], &(args[i][5]));
  155.                 args[i][0] = '/';
  156.                 args[i][1] = 'I';
  157.                 args[i][2] = args[i][4];
  158.                 args[i][3] = ':';
  159.                 args[i][4] = 0;
  160.                 strcat(args[i], args[i+1]);
  161.                 for2bak(&(args[i][1]));
  162.                 }
  163.             }
  164.  
  165.         if(mystrstr(args[i], ".lib")) //Adjust .lib paths
  166.             for2bak(args[i]);
  167.  
  168.         if(strstr(args[i], "/Fe")) //Record .exe file
  169.             {
  170.             j = 0;
  171.             for(z=3; args[i][z] != 0; z++)
  172.                 {
  173.                 if(args[i][z] == '/')
  174.                     args[i][z] = '\\';
  175.  
  176.                 exe[j++] = args[i][z];
  177.                 }
  178.             exe[j] = 0;
  179.             }
  180.  
  181.         if(csp_ptr = mystrstr(args[i], ".c")) //Record all .c files
  182.             {
  183.                         int t;
  184.  
  185. #if 0
  186.                         printf("Found a .c -> %s\n",args[i]);
  187.                         printf("RET of mystrstr -> %s\n",csp_ptr);
  188. #endif
  189.                         t = 0;
  190.  
  191.             /* for2bak(args[i]); */
  192.                         while (*( csp_ptr - 1 ) != '/' && csp_ptr > args[i]) 
  193.                {
  194.                            t++;
  195.                            csp_ptr--;
  196.                }
  197.  
  198.                         strncpy(fn[x] , csp_ptr , t );
  199.                         fn[x++][ t ] = 0;
  200.             for2bak(args[i]);
  201. #if 0
  202.                         printf("Without a .c -> %s\n",fn[x-1]);
  203. #endif
  204.             }
  205.  
  206.         if(csp_ptr = mystrstr(args[i], ".a")) //Record all .a files
  207.             {
  208.                         int t;
  209.  
  210.                         t = 0;
  211.             /*for2bak(args[i]);*/
  212.  
  213.                         while (*( csp_ptr - 1 ) != '/' && csp_ptr > args[i]) 
  214.                {
  215.                            t++;
  216.                            csp_ptr--;
  217.                }
  218.  
  219.                         strncpy(fn[y] , csp_ptr , t );
  220.                         fn[y++][ t ] = 0;
  221.             if(csp_ptr = strstr(args[i], ":"))
  222.                 for2bak(csp_ptr+1);
  223.             else
  224.                 for2bak(args[i]);
  225.             }
  226.  
  227.         argp[i] = args[i];
  228.  
  229.         }
  230.     argp[i] = (char *)NULL;
  231.  
  232.     strcpy(command, args[0]);
  233.     i = _spawnvp(_P_WAIT, command, argp);
  234.     i = errno;
  235.  
  236.     strcpy(new, exe); //Rename output.exe to output
  237.     strcpy(old, exe);
  238.     strcat(old, ".exe");
  239.     remove(new);
  240.     rename(old, new);
  241.  
  242. if(!strcmp(args[0], "lib32"))
  243.     {
  244.     strcpy(new, fn[0]); //Rename a.exe to a
  245.     strcpy(old, fn[0]);
  246.     strcat(old, ".exe");
  247.     remove(new);
  248.     rename(old, new);
  249. #if 0
  250.     for(i=0; i < x; i++) //Rename .obj to .o
  251.         {
  252.         strcpy(new, fn[i]);
  253.         strcpy(old, fn[i]);
  254.         strcat(new, ".o");
  255.         strcat(old, ".obj");
  256.         remove(new);
  257.         rename(old, new);
  258.         }
  259. #endif
  260.     for(i=0; i < y; i++) //Rename .lib to .a
  261.         {
  262.         strcpy(new, fn[i]);
  263.         strcpy(old, fn[i]);
  264.         strcat(new, ".a");
  265.         strcat(old, ".lib");
  266.         remove(new);
  267.         rename(old, new);
  268.         }
  269.     }
  270. else
  271.     for(i=0; i < x; i++) //Rename .obj to .o
  272.         {
  273.         strcpy(new, fn[i]);
  274.         strcpy(old, fn[i]);
  275.         strcat(new, ".o");
  276.         strcat(old, ".obj");
  277. #if 0
  278.                 printf("%s->%s\n",old,new);
  279. #endif
  280.         remove(new);
  281.         rename(old, new);
  282.         }
  283.  
  284.     fclose(in);
  285.     remove(directory);
  286.  
  287.     strcpy(curLibEnv, "LIB=");
  288.     strcat(curLibEnv, oldLibEnv); 
  289.     putenv(curLibEnv);
  290. }
  291.